package simulateOS.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import org.springframework.stereotype.Controller;
import simulateOS.management.device.DeviceManager;

import javax.annotation.Resource;
import java.net.URL;
import java.util.ResourceBundle;

@Controller
public class DeviceController implements Initializable {
    @FXML
    private VBox deviceBox;

    @FXML
    private Button BButton;

    @FXML
    private Button CButton;

    @FXML
    private Button AButton;

    @FXML
    private Button BdButton;

    @FXML
    private Button CdButton;

    @FXML
    private Button AdButton;

    @Resource
    private DeviceManager deviceManager;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        int i;
        double height;
        double width;
        double percent;
        for (i = 0; i < 8; ++i) {
//            height = deviceBox.getHeight();
//            width = deviceBox.getWidth();
            height = deviceBox.getPrefHeight();
            width = deviceBox.getPrefWidth();
            percent = 0.12375D;

            Label region = new Label();
            region.setId("emptyBox");
            if (i >= 0 && i <= 1) {
                region.setText("设备A：空闲");
            } else if (i >= 2 && i <= 4) {
                region.setText("设备B：空闲");
            } else {
                region.setText("设备C：空闲");
            }
            region.setPrefSize(0.9D * width, percent * height);
            region.setMinSize(0.9D * width, percent * height);
            region.setMaxSize(0.9D * width, percent * height);

            deviceBox.getChildren().add(region);
        }
    }

    /**
     * 请求设备示例
     */
//    @FXML
//    void AAction(MouseEvent event) {
//        int i = deviceManager.applyDevice(0, 12);
//        System.out.println(i);
//    }
//
//    @FXML
//    void BAction(MouseEvent event) {
//    /**
//     * 归还设备示例
//     * @param mouseEvent
//     */
//        int i = deviceManager.applyDevice(1, 13);
//        System.out.println(i);
//    }
//
//    @FXML
//    void CAction(MouseEvent event) {
//        int i = deviceManager.applyDevice(2, 14);
//        System.out.println(i);
//    }
//


    public VBox getDeviceBox() {
        return deviceBox;
    }

    public void setDevice(DeviceManager deviceManager) {
        this.deviceManager = deviceManager;
    }
}
